﻿using System;
using System.Collections.Generic;
using GeoAPI.Geometries;
using NetTopologySuite.Utilities;

namespace NetTopologySuite.Index.Strtree
{
	[Serializable]
	public abstract class AbstractNode<T, TItem> : IBoundable<T, TItem> where T : IIntersectable<T>, IExpandable<T>
	{
		protected AbstractNode(int level)
		{
			this._level = level;
		}

		public IList<IBoundable<T, TItem>> ChildBoundables
		{
			get
			{
				return this._childBoundables;
			}
		}

		protected abstract T ComputeBounds();

		public T Bounds
		{
			get
			{
				if (this._bounds == null)
				{
					this._bounds = this.ComputeBounds();
				}
				return this._bounds;
			}
		}

		public TItem Item
		{
			get
			{
				return default(TItem);
			}
		}

		public int Level
		{
			get
			{
				return this._level;
			}
		}

		public int Count
		{
			get
			{
				return this._childBoundables.Count;
			}
		}

		public bool IsEmpty
		{
			get
			{
				return this._childBoundables.Count == 0;
			}
		}

		public void AddChildBoundable(IBoundable<T, TItem> childBoundable)
		{
			Assert.IsTrue(this._bounds == null);
			this._childBoundables.Add(childBoundable);
		}

		private readonly List<IBoundable<T, TItem>> _childBoundables = new List<IBoundable<T, TItem>>();

		private T _bounds;

		private readonly int _level;
	}
}
